package com.boot.unity.api.modules.training.service.impl;

import com.boot.unity.api.common.Result;
import com.boot.unity.api.modules.training.dao.InstitutionDao;
import com.boot.unity.api.modules.training.entity.Institution;
import com.boot.unity.api.modules.training.service.InstitutionService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
/**
 * @author anonymous
 *
 * @create 2020-06-06 22:05:54
 */
@Service
@AllArgsConstructor
public class InstitutionServiceImpl implements InstitutionService {
    private final InstitutionDao institutionDao;

    @Override
    public Result save(Institution institution) {
        String inscode = institution.getInscode();
        Institution check= institutionDao.getByInscode(inscode);
        int num;
        if (check == null){
            num = institutionDao.save(institution);
        }else {
            num = institutionDao.updateByInscode(institution);
        }
        if (num > 0){
            return Result.success();
        }
        return Result.fail();
    }
}
